﻿using PeiYue.IRepository.Base;
using PeiYue.IServices.Purchase;
using PeiYue.Model.Models.Purchase;
using PeiYue.Services.BASE;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace PeiYue.Services.Purchase
{
    public class SrmSortingRecord: BaseServices<SrmSortingRecordDao>, ISrmSortingRecord
    {
        IBaseRepository<SrmSortingRecordDao> _dal;
        public SrmSortingRecord(IBaseRepository<SrmSortingRecordDao> dal)
        {
            this._dal = dal;
            base.BaseDal = dal;
        }
        public async Task<int> DeleteBySaleId(int saleId,string supplierCode="")
        {
            string sql= "update  [oms].[dbo].[oms_srm_sorting_record] set Status=0 where OrderDetailId=@saleId and SupplierCode=@supplierCode ";
            return await _dal.ExecuteCommand(sql, new { saleId = saleId, supplierCode= supplierCode });
        }
        public async Task<int> DeleteByFId(int fID)
        {
            string sql = "update  [oms].[dbo].[oms_srm_sorting_record] set Status=0 where fID=@fID";
            return await _dal.ExecuteCommand(sql, new { fID = fID });
        }
        /// <summary>
        /// 缺货
        /// </summary>
        /// <param name="fID"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task<bool> LackGoods(int fID,long userId)
        {
            string sql = "update [oms].[dbo].[oms_srm_sorting_record] set Flag=2,Qty=0,PackQty=0,UpdateUser=@userId,UpdateTime=getdate() where FID=@fID ";
            return (await _dal.ExecuteCommand(sql, new { fID = fID,userId= userId }))>0;
        }

    }
}
